#include <stdio.h>

int compare(int  a1,int  a2){
    if(a1<a2)
    {
        return 1;
    }
    return 0;
}

void sort(int* array,int n)
{
    int i,j;
    int** queue=new int*[n];
    int start=0;
    int end=1;
    queue[start]=new int[2];
    queue[start][0]=0;
    queue[start][1]=n;
    //开始快排
    while (start<end)
    {
        int s=queue[start][0];
        int e=queue[start][1];
        
        i=s;
        j=e-1;
        int tmpIndex=j;
        int tmp=array[tmpIndex];
        while (i<j)
        {
            if(tmpIndex==j)
            {
                //前面大于后面
                if(compare(array[i],tmp))
                {
                    array[tmpIndex]=array[i];
                    tmpIndex=i;
                    // tmp=array[tmpIndex];
                }
            }
            else
            {
                //前面大于后面
                if(compare(tmp,array[j]))
                {
                    array[tmpIndex]=array[j];
                    tmpIndex=j;
                    // tmp=array[tmpIndex];
                }
            }

            if(tmpIndex==j)
            {
                i++;
            }
            else{
                j--;
            }

            
        }

        array[i]=tmp;

        start++;
        if(s<i)
        {
            end++;
            queue[end-1]=new int[2];
            queue[end-1][0]=s;
            queue[end-1][1]=i;
        }

        if(i+1<e)
        {
            end++;
            queue[end-1]=new int[2];
            queue[end-1][0]=i+1;
            queue[end-1][1]=e;
        }
    }

    for(i=0;i<end;i++)
    {
        delete queue[i];
    }
    delete queue;
}

int searchIndex(int* input1,int* inUse,int n,int searchStart,int resetNum,int limit)
{
    if(limit<=0)
    {
        return n;
    }
    int index=n;
    for(int i=searchStart;i<n;i++)
    {
        if(inUse[i]==0&&input1[i]<=resetNum&&input1[i]<=limit)
        {
            index=i;
            break;
        }
    }

    return index;
}

void printArray2(int* input1,int* searchValue,int* resetValue,int n)
{
    for(int i=0;i<n;i++)
    {
        printf("%d\t%d\n",input1[searchValue[i]],resetValue[i]);
    }
    printf("\n");
}

void printArray3(int* input1,int* inUse,int n)
{
    for(int i=0;i<n;i++)
    {
        if(!inUse[i])
        {
            printf("%d\t",input1[i]);
        }
        
    }
    printf("\n\n");
}

int dfs(int* input1,int n,int num){
    int* inUse=new int[n];
    int* searchValue=new int[n];
    int* resetValue=new int[n];
    int* startValue=new int[n];
    int i;
    for(i=0;i<n;i++)
    {
        inUse[i]=0;
    }
    searchValue[0]=0;
    resetValue[0]=num-input1[0];
    startValue[0]=input1[0];
    inUse[0]=1;
    int len=1;

    printf("%d\n",num);

    while (len>0&&len<n)
    {
        //完成了一个小木棍的拼接
        if(resetValue[len-1]==0)
        {
            for(i=0;i<n;i++)
            {
                if(!inUse[i])
                {
                    if(input1[i]>startValue[len-1])
                    {
                        len=0;
                        break;
                    }

                    searchValue[len]=i;
                    resetValue[len]=num-input1[i];
                    startValue[len]=input1[i];
                    inUse[i]=1;
                    len++;
                    printArray2(input1,searchValue,resetValue,len);
                    printArray3(input1,inUse,n);
                    printf("%d\n",len);
                    break;
                }
            }
        }
        else{
            //寻找下一个木棍
            int index=n;
            int start=searchValue[len-1]+1;
            int limit=num;
            do
            {
                index=searchIndex(input1,inUse,n,start,resetValue[len-1],limit);
                //没有找到下一个 当前的木棍出栈 找下一个木棍
                if(index>=n)
                {
                    //下一个木棍搜索开始位置
                    start=searchValue[len-1]+1;
                    //下一次只能搜索比当前小的木棍
                    limit=input1[searchValue[len-1]]-1;

                    //将当前位置设置成没有使用
                    inUse[searchValue[len-1]]=0;
                    len--;
                    // printArray2(input1,searchValue,resetValue,len);
                }
                //找到了下一个入栈
                else{
                    searchValue[len]=index;
                    resetValue[len]=resetValue[len-1]-input1[index];
                    startValue[len]=startValue[len-1];
                    inUse[index]=1;
                    len++;
                    // printArray2(input1,searchValue,resetValue,len);
                }
            }while (index>=n&&len>0);
        }
    }
    


    delete inUse;
    delete searchValue;
    delete resetValue;
    return len>=n;
}

void printArray(int* input1,int n)
{
    for(int i=0;i<n;i++)
    {
        printf("%d\n",input1[i]);
    }
    printf("\n");
}

int main(){
    int n;
    int sum=0,i,j;
    scanf("%d",&n);
    int* input=new int[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&input[i]);
        sum+=input[i];
    }
    sort(input,n);

    // printArray(input,n);
    
    int result=sum;

    for(i=input[0];i<sum;i++)
    {
        if(sum%i==0)
        {
            if(dfs(input,n,i))
            {
                result=i;
                break;
            }
        }
    }

    printf("%d\n",result);
    delete input;
    return 0;
}